package com.itlong.cloud.controller.u8basedata;

import com.itlong.cloud.POJO.DTO.operate.OperateU8BaseDataDTO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.abstracts.BaseController;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.project.operate.IOperateU8BaseDataServiceClient;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.utils.network.http.HttpProtocolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * <desc>
 *      运营-U8基础数据管理控制器
 * </desc>
 *
 * @createDate 2020/12/02
 */
@RestController
@RequestMapping("/u8/synchronize/baseData")
@RefreshScope
public class OperateU8BaseDataController extends BaseController {

    @Autowired
    private IOperateU8BaseDataServiceClient iOperateU8BaseDataServiceClient;

    /**
     * <desc>
     *      获取业务员部门列表
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author Juguang.S
     * @createDate 2020/12/02
     */
    @ResponseBody
    @PostMapping("getDepartmentPage")
    public Object getLogPage(){
        try {
            HttpServletRequest request=((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            OperateU8BaseDataDTO operateU8BaseDataDTO= HttpProtocolUtil.parseRequestParamToDTO(OperateU8BaseDataDTO.class,request);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), iOperateU8BaseDataServiceClient.getDepartmentPage(operateU8BaseDataDTO));
        } catch (Exception e) {
            throw new DataAccessException("【运营-U8基础数据管理getLogPage】获取业务员部门列表失败",e);
        }
    }

    /**
     * <desc>
     *      获取业务员列表
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author Juguang.S
     * @createDate 2020/12/02
     */
    @ResponseBody
    @PostMapping("getSalesPage")
    public Object getSalesPage(){
        try {
            HttpServletRequest request=((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            OperateU8BaseDataDTO operateU8BaseDataDTO= HttpProtocolUtil.parseRequestParamToDTO(OperateU8BaseDataDTO.class,request);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), iOperateU8BaseDataServiceClient.getSalesPage(operateU8BaseDataDTO));
        } catch (Exception e) {
            throw new DataAccessException("【运营-U8基础数据管理getSalesPage】获取业务员部门列表失败",e);
        }
    }

    /**
     * <desc>
     *      获取客户列表
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author Juguang.S
     * @createDate 2020/12/02
     */
    @ResponseBody
    @PostMapping("getCustomerPage")
    public Object getCustomerPage(){
        try {
            HttpServletRequest request=((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            OperateU8BaseDataDTO operateU8BaseDataDTO= HttpProtocolUtil.parseRequestParamToDTO(OperateU8BaseDataDTO.class,request);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), iOperateU8BaseDataServiceClient.getCustomerPage(operateU8BaseDataDTO));
        } catch (Exception e) {
            throw new DataAccessException("【运营-U8基础数据管理getCustomerPage】获取客户列表失败",e);
        }
    }
}
